package com.thkj.modules.user.service.impl;

import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.thkj.modules.dao.DevicesMapper;
import com.thkj.modules.user.entity.Device;
import com.thkj.modules.user.service.DevicesService;

import dp.service.BaseService;

@Service
public class DevicesServiceImpl extends BaseService implements DevicesService {


    //消毒时间标准
    private static final int standard = 2;

    @Autowired
    private DevicesMapper devicesMapper;

    @Override
    public void insert(Device devices) {
        devicesMapper.insert(devices);
    }

    @Override
    public Device queryById(String id) {
        return devicesMapper.selectByPrimaryKey(id);
    }

    @Override
    public Device queryByDevice(Device devices) {
        return devicesMapper.selectOne(devices);
    }

    @Override
    public int queryCountByDevice(Device devices) {
        return devicesMapper.selectCount(devices);
    }

    @Override
    public List<Map> queryDisinfectByIndividualId(String individual_id, String timeStr) {
        List<Map> list = devicesMapper.queryDisinfectDayByIndividualId(individual_id, timeStr);
        for (Map map : list) {
            Double duration = (Double) map.get("duration");
            if (duration != null) {
                if (duration > standard) { //合格
                    map.put("state", 1);
                } else { //不合格
                    map.put("state", 2);
                }
            } else {
                map.put("state", 2);
                map.put("duration", 0.00);
            }

            Double duration2 = (Double) map.get("duration");

            DecimalFormat df = new DecimalFormat("0.00");
            map.put("degree", df.format((duration2 * 880d) / 100));
        }
        return list;
    }
}